
var MY_NCOV_REPORT_COMM = (function() {

    function initNcovReportComm(id) {
        var modalHtml = getModalHtml();

        var $ncovReportModal = $(modalHtml).modal();
        $ncovReportModal.on('shown.bs.modal',function (e) {
            // 初始化数据
            showInfo($ncovReportModal,id);

        });

        $ncovReportModal.on('hidden.bs.modal',function (e) {
            $ncovReportModal.modal('hide');
            $ncovReportModal.remove();
        });
    }

    /**
     * 显示上报信息
     * */
    function showInfo( $modal,id) {
        var params = {};
        params.id = id;

        $.ajax({
            type: "POST",
            url: "invs_ncov_report.do/load_detail",
            dataType: "json",
            data: params,
            async: false,
            success: function(data) {
                if (!WeKnow.filterAjaxResult(data)) return false; // session过期check
                if (data.errcode == 0) {
                    // 显示数据
                    initFormData($modal,data);
                }
            },
            error: function() {
                WeKnow.systemMsg("系统异常");
            }
        });
    }

    function initFormData($modal,data) {
        var report = data.data;

        $modal.find('input').prop('readonly','readonly');
        $modal.find('input').prop('disabled','disabled');
        $modal.find('select').prop('disabled','disabled');
        // 诊所名称
        $modal.find('input[name="institution_name"]').val(report.institutionName);
        // 医生姓名
        $modal.find('input[name="doctor_name"]').val(report.doctorName);
        // 诊所地址
        $modal.find('input[name="institution_addr"]').val(report.institutionAddr);
        // 医生联系方式
        $modal.find('input[name="doctor_phone"]').val(report.doctorPhone);
        // 姓名
        $modal.find('input[name="name"]').val(report.name);
        //年龄
        $modal.find('input[name="age"]').val(report.age);
        // 性别
        $modal.find('input[name="gender"]').filter('[value="'+ report.gender +'"]').prop("checked", true);
        //手机号码
        $modal.find('input[name="phone"]').val(report.phone);
        //身份证号
        $modal.find('input[name="id_card"]').val(report.idCard);

        // 省市县
        var $province = $modal.find('select[name="province"]');
        var $city = $modal.find('select[name="city"]');
        var $county = $modal.find('select[name="county"]');
        //省
        if ( report.province ){
            $province.data('defaultvalue',report.province);
        }
        //市
        if ( report.city ){
            $city.data('defaultvalue',report.city);
        }
        //县
        if ( report.county ){
            $county.data('defaultvalue',report.county);
        }
        if (!$province.find('option').length) {// 第一次初始化
            WN_DISTRICT.init($province, $city, $county);
        }


        //详细地址
        $modal.find('input[name="location"]').val(report.location);
        //发热
        if ( report.fever == 1){
            $modal.find('input[name="fever"]').prop('checked',true);
        } else {
            $modal.find('input[name="fever"]').prop('checked',false);
        }
        //体温
        if (report.temperature !=null ){
            $modal.find('input[name="temperature"]').val(report.temperature);
        }
        if ( report.rhinobyon == 1){
            $modal.find('input[name="rhinobyon"]').prop('checked',true);
        } else {
            $modal.find('input[name="rhinobyon"]').prop('checked',false);
        }
        // 咽痛
        if ( report.pharyngalgia == 1){
            $modal.find('input[name="pharyngalgia"]').prop('checked',true);
        } else {
            $modal.find('input[name="pharyngalgia"]').prop('checked',false);
        }
        //咳嗽
        if ( report.dryCough == 1){
            $modal.find('input[name="dry_cough"]').prop('checked',true);
        } else {
            $modal.find('input[name="dry_cough"]').prop('checked',false);
        }
        //乏力
        if ( report.weak == 1){
            $modal.find('input[name="weak"]').prop('checked',true);
        } else {
            $modal.find('input[name="weak"]').prop('checked',false);
        }
        //流涕
        if ( report.runningNose == 1){
            $modal.find('input[name="running_nose"]').prop('checked',true);
        } else {
            $modal.find('input[name="running_nose"]').prop('checked',false);
        }
        //腹泻
        if (report.diarrhea == 1){
            $modal.find('input[name="diarrhea"]').prop('checked',true);
        } else {
            $modal.find('input[name="diarrhea"]').prop('checked',false);
        }
        // 呼吸急促
        if ( report.polypnea == 1){
            $modal.find('input[name="polypnea"]').prop('checked',true);
        } else {
            $modal.find('input[name="polypnea"]').prop('checked',false);
        }
        //其它症状
        if (report.complain && report.complain.length){
            $modal.find('input[name="complain"]').val(report.complain);
        }
        //肺部影像
        if (report.imaging && report.imaging.length) {
            $modal.find('input[name="imaging"]').val(report.imaging);
        }
        //血常规
        if (report.blood && report.blood.length){
            $modal.find('input[name="blood"]').val(report.blood);
        }
        // 过去14天，有无接触确诊或疑似新型冠状病毒患者或密切接触者
        $modal.find('input[name="touch_infected_st"]').filter('[value="'+ report.touchInfectedSt +'"]').prop("checked", true);
        // 过去14天，有无接触来自湖北、温州、黄岩、温岭的人员
        $modal.find('input[name="touch_epidemic_st"]').filter('[value="'+ report.touchEpidemicSt +'"]').prop("checked", true);
        //过去14天，所居住小区是否有确诊或疑似新型冠状病毒患者或密切接触者
        $modal.find('input[name="housing_infected_st"]').filter('[value="'+ report.housingInfectedSt +'"]').prop("checked", true);
        //过去14天，有无出现在确诊新型冠状病毒的公众场所或乘坐共同交通
        $modal.find('input[name="vehicle_st"]').filter('[value="'+ report.vehicleSt +'"]').prop("checked", true);
        // 过去14天，去过的地方(至少具体到区县)
        if ( report.placesBeen && report.placesBeen.length){
            $modal.find('input[name="places_been"]').val(report.placesBeen);
        }
        // 不显示上报按钮
        $modal.find('button[name="reportInfo"]').hide();

    }

    /**
     * 生成详细信息模态框
     * */
    function getModalHtml() {
        e = '<div class="modal fade ncov_report_modal" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel">\
            <div class="modal-dialog modal-lg" role="document">\
                <div class="modal-content">\
                    <div class="modal-header" style="background-color: #f5f5f5;">\
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>\
                        <h4 class="modal-title">新冠疑似信息上报</h4>\
                    </div>\
                    <div class="modal-body">\
			<div class="text-center">\
				<p class="text-danger">冠状肺炎疫情期间，发热、咳嗽病人需上报详细信息。为了您和大家的安全，谢谢配合。</p>\
			</div>\
			<div class="container-fluid">\
				<div class="row">\
					<div class="col-xs-2 text-right"><span class="required">患者姓名</span></div>\
					<div class="col-xs-2"><input type="text" class="form-control" style="width: 105%" name="name" maxlength="15" autocomplete="off" ></div>\
					<div class="col-xs-2 text-right"><span class="required">年龄</span></div>\
					<div class="col-xs-2"><input type="text" class="form-control" name="age" maxlength="5" autocomplete="off" ></div>\
					<div class="col-xs-2 text-right"><span class="required">性别</span></div>\
					<div class="col-xs-2">\
						<label class="radio-inline"><input type="radio" name="gender" value="1" checked="checked" autocomplete="off">男</label>\
						<label class="radio-inline"><input type="radio" name="gender" value="2" autocomplete="off">女</label>\
					</div>\
				</div>\
				<div class="row">\
					<div class="col-xs-2 text-right"><span class="required">联系电话</span></div>\
					<div class="col-xs-2"><input type="text" class="form-control" name="phone" style="width: 105%" maxlength="11" autocomplete="off" ></div>\
					<div class="col-xs-2 text-right"><span class="required">身份证号</span></div>\
					<div class="col-xs-3"><input type="text" class="form-control" name="id_card" maxlength="18" autocomplete="off" ></div>\
				</div>\
				<div class="row">\
					<div class="col-xs-2 text-right"><span class="required">住址</span></div>\
					<div class="col-xs-10">\
					    <div style="display: inline-block;width: 44%;">\
						<select class="form-control" style="width: auto; display: inline-block;" name="province" ></select>\
						<select class="form-control" style="width: auto; display: inline-block;" name="city"></select>\
						<select class="form-control" style="width: auto; display: inline-block;" name="county"></select></div>\
						<div style="display: inline-block;width: 55%;"><input type="text" style="margin-left: -5.1%;" class="form-control" name="location" maxlength="255" placeholder="详细地址" autocomplete="off" ></div>\
					</div>\
				</div>\
				<div class="cut-off-line"></div>\
				<div class="row">\
					\<div class="col-xs-2 text-right"></div>\
					<div class="col-xs-10 text-left">\
						<label class="checkbox-inline" style="width:25%">\
						  <input type="checkbox" name="fever" value="1"> 发热（体温）≥37.3°C\
						</label>\
						<label class="checkbox-inline" style="width:20%">\
						  <input type="checkbox" name="rhinobyon" value="1"> 鼻塞\
						</label>\
						<label class="checkbox-inline" style="width:20%">\
						  <input type="checkbox" name="pharyngalgia" value="1"> 咽痛\
						</label>\
						<label class="checkbox-inline" style="width:20%">\
						  <input type="checkbox" name="dry_cough" value="1"> 咳嗽\
						</label>\
					</div>\
				</div>\
				<div class="row">\
					<div class="col-xs-2 text-right"></div>\
					<div class="col-xs-10 text-left">\
						<label class="checkbox-inline" style="width:25%">\
						  <input type="checkbox" name="weak" value="1">乏力\
						</label>\
						<label class="checkbox-inline" style="width:20%">\
						  <input type="checkbox" name="running_nose" value="1"> 流涕\
						</label>\
						<label class="checkbox-inline" style="width:20%">\
						  <input type="checkbox" name="diarrhea" value="1"> 腹泻\
						</label>\
						<label class="checkbox-inline" style="width:20%">\
						  <input type="checkbox" name="polypnea" value="1"> 呼吸急促\
						</label>\
					</div>\
				</div>\
				<div class="row">\
					<div class="col-xs-2 text-right"><span class="required">体温</span></div>\
					<div class="col-xs-2 text-left">\
						<input type="text" class="form-control" name="temperature" maxlength="15" autocomplete="off" >\
					</div>\
					<div class="col-xs-2 text-right"><span>其它症状</span></div>\
					<div class="col-xs-6 "><input type="text" class="form-control" name="complain" autocomplete="off" maxlength="255" ></div>\
				</div>\
				<div class="row">\
					<div class="col-xs-2 text-right"><span>肺部影像</span></div>\
					<div class="col-xs-10 "><input type="text" class="form-control" autocomplete="off" name="imaging" maxlength="255" placeholder=""></div>\
				</div>\
				<div class="row">\
					<div class="col-xs-2 text-right"><span>血常规</span></div>\
					<div class="col-xs-10 "><input type="text" class="form-control" autocomplete="off" name="blood" maxlength="255" placeholder=""></div>\
				</div>\
				<div class="cut-off-line"></div>\
				<div class="row">\
					<div class="col-xs-8 col-md-offset-1 text-left"><span>1、过去14天，有无接触确诊或疑似新型冠状病毒患者或密切接触者</span></div>\
					<div class="col-xs-3">\
						<label class="radio-inline"><input type="radio" name="touch_infected_st" value="1">是</label>\
						<label class="radio-inline"><input type="radio" name="touch_infected_st" value="0"  checked="checked" > 否</label>\
					</div>\
				</div>\
				<div class="row">\
					<div class="col-xs-8 col-md-offset-1 text-left"><span>2、过去14天，有无接触来自湖北、温州、黄岩、温岭、台州、河南信阳、南阳的人员</span></div>\
					<div class="col-xs-3">\
						<label class="radio-inline"><input type="radio" name="touch_epidemic_st" value="1">是</label>\
						<label class="radio-inline"><input type="radio" name="touch_epidemic_st" value="0"  checked="checked"> 否</label>\
					</div>\
				</div>\
				<div class="row">\
					<div class="col-xs-8 col-md-offset-1 text-left"><span>3、过去14天，所居住小区/单位是否有确诊或疑似新型冠状病毒患者或密切接触者</span></div>\
					<div class="col-xs-3">\
						<label class="radio-inline"><input type="radio" name="housing_infected_st" value="1">是</label>\
						<label class="radio-inline"><input type="radio" name="housing_infected_st" value="0"  checked="checked"> 否</label>\
					</div>\
				</div>\
				<div class="row">\
					<div class="col-xs-8 col-md-offset-1 text-left"><span>4、过去14天，有无出现在确诊新型冠状病毒的公众场所或乘坐共同交通</span></div>\
					<div class="col-xs-3">\
						<label class="radio-inline"><input type="radio" name="vehicle_st" value="1">是</label>\
						<label class="radio-inline"><input type="radio" name="vehicle_st" value="0"  checked="checked"> 否</label>\
					</div>\
				</div>\
				<div class="row">\
					<div class="col-xs-8 col-md-offset-1 text-left"><span>5、过去14天，去过的地方(至少具体到区县)</span></div>\
					<div class="col-xs-3">\
						<input type="text" class="form-control" name="places_been" maxlength="255" placeholder="">\
					</div>\
				</div>\
				<div class="row">\
                    <div class="col-xs-2 text-right"><span class="required">医疗机构名称</span></div>\
                    <div class="col-xs-4"><input type="text" class="form-control" name="institution_name" maxlength="18" autocomplete="off" ></div>\
                    <div class="col-xs-2 text-right"><span class="required">医疗机构地址</span></div>\
                    <div class="col-xs-4"><input type="text" class="form-control" name="institution_addr" maxlength="25" autocomplete="off" ></div>\
                </div>\
                <div class="row">\
                    <div class="col-xs-2 text-right"><span class="required">医生姓名</span></div>\
                    <div class="col-xs-4"><input type="text" class="form-control" name="doctor_name" maxlength="18" autocomplete="off" ></div>\
                    <div class="col-xs-2 text-right"><span class="required">联系方式</span></div>\
                    <div class="col-xs-4"><input type="text" class="form-control" name="doctor_phone" maxlength="20" autocomplete="off" ></div>\
                </div>\
				<div class="cut-off-line"></div>\
				<div class="row">\
					<div class="col-xs-12 text-center">\
						<button type="button" style="width: 14%;" class="btn btn-primary" name="reportInfo">信息上报</button>\
					</div>\
				</div>\
			</div>\
                    </div>\
                </div>\
            </div>\
        </div>';
        return e;
    }

    // add by zhengxb 2019.6.21  end ---------------------------------------------------------
    return {
        initNcovReportComm:initNcovReportComm
    }
})();